#!/usr/bin/env bash

model_root="$HOME/onnx-model/public-model-zoo"

function usage() {
  echo "Usage: $( basename $0 ) [ -m <model_name> | -h ]"
  echo -e "\t-m <model_name>: 要处理的模型主名，缺省处理${model_root}下所有模型"
  echo -e "\t-h: 输出本信息"
  exit 0
}

while getopts "hm:" arg
do
    case $arg in
        m)
          targetModel=${OPTARG}
          ;;
        *)
          usage
          ;;
    esac
done

for chip in TX510 TX511 DT53 DT56 DT57
do
  for modelPath in "${model_root}"/*
  do
    modelName="$( basename -s .onnx ${modelPath} )"
    if [ -n "${targetModel}" -a "${targetModel}" != "${modelName}" ]
    then
      continue
    fi
    echo ./run_quantization.py -m "${modelPath}" -r quant -if infer_auto --chip ${chip} -s "tmp/${chip}"  
    ./run_quantization.py -m "${modelPath}" -r quant -if infer_auto --chip ${chip} -s "tmp/${chip}" 2>&1 | tee logs/${modelName}_${chip}.log
  done
done
